{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4208dd34-933c-482b-ae53-9d69614ed282",
   "metadata": {},
   "source": [
    "### 图像旋转变换"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b740300a-89e3-45dd-b91e-8f3bab4fc3e5",
   "metadata": {},
   "source": [
    "- 图片尺寸为640x427\n",
    "- 旋转180°的运行时耗约是0.003s\n",
    "- 反转过去后的图像C与原图像的灰度差异有，值约为0.17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c1a6590b-f75e-4fa5-8f87-6b97eb8db0df",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time taken for rotation: 0.0030219554901123047 seconds\n",
      "CPU times: total: 78.1 ms\n",
      "Wall time: 3.97 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "import time\n",
    "time.sleep(2)\n",
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 加载图像\n",
    "img = cv2.imread('bed.jpg')\n",
    "\n",
    "# 确定旋转中心\n",
    "(h, w) = img.shape[:2]\n",
    "center = (w // 2, h // 2)\n",
    "\n",
    "# 确定旋转角度\n",
    "angle = 180\n",
    "# 计时开始\n",
    "start_time = time.time()\n",
    "# 执行旋转变换\n",
    "M = cv2.getRotationMatrix2D(center, angle, 1.0)\n",
    "rotated = cv2.warpAffine(img, M, (w, h))\n",
    "# 计时结束\n",
    "end_time = time.time()\n",
    "# 输出计算时间\n",
    "print(\"Time taken for rotation: %s seconds\" % (end_time - start_time))\n",
    "cv2.imshow('pr_rotated',rotated)\n",
    "cv2.waitKey(0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b4957a82-f918-4ed2-8c5f-8540640c72ac",
   "metadata": {
    "tags": []
   },
   "outputs": [
    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DB+vtt9/mFGoA18TsCdBzeBVg3nnnnXbboqOjVVJScs11xMTEaMuWLVetSU5O1v79+73pGgAA6EH4LSQAAGA5BBgAAGA5BBgAAGA5BBgAaAcHBQP+iwADAAAshwADAFdg5gXwfwQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYAABgOQQYALiKoQsKNHRBga+7AeAKBBgA3QIhA+hZCDAAAMByCDAAAMByCDAAAMByvAowa9euVUJCgux2u+x2u5xOpz7//HOz/fz588rMzNSgQYM0YMAATZo0SXV1dR7rqKmpUUZGhvr376/w8HDNmzdPFy9e9KgpLi7WvffeK5vNpmHDhikvL6/jWwgAALodrwLM4MGDtWLFCpWXl+ubb77RY489pgkTJqiyslKSNHfuXH322Wf66KOPVFJSoh9++EETJ040H3/p0iVlZGSoublZe/bs0fvvv6+8vDwtWrTIrKmurlZGRoYeffRRVVRUaM6cOXrxxRe1bdu2TtpkAABgdb29KX7iiSc8bv/617/W2rVrVVZWpsGDB+udd97Rhg0b9Nhjj0mS3nvvPY0cOVJlZWV68MEHtX37dh0+fFg7duxQRESExowZo+XLl2v+/PlasmSJgoKCtG7dOsXGxmrVqlWSpJEjR2r37t1avXq10tLSOmmzAQCAlXX4GJhLly7pww8/VGNjo5xOp8rLy3XhwgWlpKSYNSNGjNCQIUNUWloqSSotLVV8fLwiIiLMmrS0NLndbnMWp7S01GMdrTWt62hPU1OT3G63xwIAALonrwPMwYMHNWDAANlsNs2cOVObN29WXFycXC6XgoKCFBIS4lEfEREhl8slSXK5XB7hpbW9te1qNW63W+fOnWu3Xzk5OQoODjaX6OhobzcNAABYhNcBZvjw4aqoqNDevXs1a9YsTZ06VYcPH+6KvnklOztbDQ0N5nL8+HFfdwkAAHQRr46BkaSgoCANGz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Xs2bNmzbXeEy5evGiMGjXKSE1NNSoqKoytW7cat912m5Gdne2LTfIr1xrfI0eOGMuWLTO++eYbo7q62vj000+N22+/3Rg7dqy5Dn8bXwJMB7zxxhvGkCFDjKCgIOOBBx4wysrKfN0lS3rqqaeMyMhIIygoyPinf/on46mnnjKOHDlitp87d874t3/7N+PWW281+vfvb/z0pz81amtrfdhj//bFF18Ykn60TJ061TCMv59K/R//8R9GRESEYbPZjHHjxhlVVVUe6zhx4oTxzDPPGAMGDDDsdrvx/PPPG6dPn/bB1vifq43v2bNnjdTUVOO2224z+vTpY8TExBjTp0//0Rcbxrd9bY2tJOO9994za67nPeHYsWNGenq60a9fPyMsLMx46aWXjAsXLtzkrfE/1xrfmpoaY+zYsUZoaKhhs9mMYcOGGfPmzTMaGho81uNP4xtgGIZx8+Z7AAAAbhzHwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMshwAAAAMv5fzF+hso+7C87AAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "灰度值差异：0.1704771662763466\n"
     ]
    }
   ],
   "source": [
    "# 将旋转后的图像转回原来的方向\n",
    "M_inv = cv2.getRotationMatrix2D(center, -angle, 1.0)\n",
    "rotated_back = cv2.warpAffine(rotated, M_inv, (w, h))\n",
    "\n",
    "# cv2.imshow('Rotated Image', rotated_back)\n",
    "# cv2.waitKey(0)\n",
    "\n",
    "# 将原始图像和旋转后的图像转换为灰度图像\n",
    "gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
    "gray_rotated_back = cv2.cvtColor(rotated_back, cv2.COLOR_BGR2GRAY)\n",
    "\n",
    "#计算该图像直方图\n",
    "hist = np.zeros((256,), dtype=np.int_)\n",
    "for i in range(gray_img.shape[0]):\n",
    "    for j in range(gray_img.shape[1]):\n",
    "        hist[gray_img[i, j]] += 1\n",
    "\n",
    "# 绘制直方图\n",
    "plt.bar(range(256), hist)\n",
    "plt.show()\n",
    "\n",
    "# 计算两幅灰度图像之间的均方差（MSE）\n",
    "mse = np.mean((gray_img - gray_rotated_back) ** 2)\n",
    "\n",
    "# 打印灰度值差异\n",
    "print(f\"灰度值差异：{mse}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
